//
//  NetDAO.m
//  StartFortuneNew
//
//  Created by 邹渊峰 on 14-10-17.
//  Copyright (c) 2014年 niit. All rights reserved.
//

#import "NetDAO.h"
#import "Net.h"
#import "AFHTTPRequestOperationManager.h"

static NetDAO *instance=nil;

@implementation NetDAO



+(NetDAO *)sharedNetDAO
{
    if (instance==nil)
    {
        instance=[[NetDAO alloc]init];
    }
    return instance;
}




//获取数据
-(void)getData
{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getID:) name:kNotificationPassID object:nil];
   
    NSString *str=[NSString stringWithFormat:@"http://api.uihoo.com/astro/astro.http.php?fun=day&id=%@&format=json",self.a] ;
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr POST:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        self.list = responseObject;
        for (int i = 0; i < self.list.count-2; i++) {
            NSLog(@"%@ %@ %@",[self.list[i] objectForKey:@"title"],[self.list[i] objectForKey:@"rank"],[self.list[i] objectForKey:@"value"]);
        }
        [[NSNotificationCenter defaultCenter]postNotificationName:kNotificationGetDataSuccessDAO object:self.list];
        NSLog(@"%@",self.list[self.list.count-1]);//显示时间
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
    
     
}

-(void)getID:(NSNotification *)n
{
    self.a=n.object;
    
}



@end
